package com.xn.monitor.common;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Created by yangshoujun on 2017/7/15 上午12:58.
 */
public class MonitorUtils {

    public static Integer getPid() {
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        String name = runtime.getName();
        Integer pid = Integer.parseInt(name.substring(0, name.indexOf('@')));
        return pid;
    }

    public static String getServerIpAddress() {
        try {
            InetAddress address = InetAddress.getLocalHost();
            return address.getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return "";
        }
    }
}
